﻿using System.Threading;
using System.Threading.Tasks;
using ZlenStack.EventBus.Events;

namespace ZlenStack.EventBus.Abstractions
{
    public interface IEventBus
    {
        /// <summary>
        /// 发布事件
        /// </summary>
        /// <returns></returns>
        Task PublishAsync(IntegrationEvent @event, CancellationToken cancellationToken = default);

        /// <summary>
        /// 订阅事件
        /// </summary>
        void Subscribe<T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler<T>;

        /// <summary>
        /// 退订事件
        /// </summary>
        void Unsubscribe<T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler<T>;

        /// <summary>
        /// 订阅动态事件
        /// </summary>
        void SubscribeDynamic<TH>(string eventName) where TH : IDynamicIntegrationEventHandler;

        /// <summary>
        /// 退订动态事件
        /// </summary>
        void UnsubscribeDynamic<TH>(string eventName) where TH : IDynamicIntegrationEventHandler;
    }
}
